﻿using System;
using System.Collections;
using System.Data;

namespace ControlExplorer.samples.Filter
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, System.EventArgs e)
    {
      if (IsPostBack)
        return;

      //Generate the dataset
      DataSet ds = new DataSet();
      string f = MapPath("..\\Freezing\\authors.xml");
      ds.ReadXml(f);

      //Load a skin
      //FarPoint.Web.Spread.DefaultSkins.GetAt(13).Apply(FpSpread1.Sheets[0]);
      //FpSpread1.CommandBar.BackColor = Color.Wheat;

      //Bind
      FpSpread1.DataSource = ds;

      //Set up filtering for column 6 - 'State'
      FarPoint.Web.Spread.HideRowFilter hideRowFilter = new FarPoint.Web.Spread.HideRowFilter(FpSpread1.ActiveSheetView);
      hideRowFilter.ShowFilterIndicator = false; //- Hide Spread's built-in column header filter
      hideRowFilter.AddColumn(6);
      FpSpread1.ActiveSheetView.RowFilter = hideRowFilter; //Apply the filter

      //Add the filtering items to the combobox
      ArrayList filterItemList = FpSpread1.ActiveSheetView.GetDropDownFilterItems(6);
      if (filterItemList != null)
        for (int i = 0; i < filterItemList.Count; i++)
          DropDownList1.Items.Add(filterItemList[i].ToString());
      this.FpSpread1.UseClipboard = false;
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.FpSpread1.ButtonCommand += new FarPoint.Web.Spread.SpreadCommandEventHandler(this.FpSpread1_ButtonCommand);

    }
    #endregion

    private void FpSpread1_ButtonCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
    {
      //Do the filtering
      if (e.CommandName.StartsWith("filter"))
      {
        int n = e.CommandName.IndexOf(".") + 1;
        //Get the filter string
        string state = e.CommandName.Substring(n);

        //Filter
        FpSpread1.ActiveSheetView.AutoFilterColumn(6, state);
      }
    }
   
  }
}